var stdGetHeader = {
    get: {
        method: 'GET',
        headers: {'Content-Type': 'application/json;charset=utf-8'}
    }
};

var stdPostHeader = {
    save: {
        method: 'POST'
    }
};

angular.module('mis.weixinManager.wishService', ['ngResource'])
    .factory('Wish', function ($resource) {
        return {
            getWishList: function(opt, page, size, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/getWishList/{1}/{2}'.format(backOfficeHost,page,size), {}, stdPostHeader);
                opt = JSON.stringify(opt);
                req.save(opt, function (data) {
                    callback(data.result.message, data.data);
                })
            },
            getUserWishList: function(opt, page, size, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/getUserWishList/{1}/{2}'.format(backOfficeHost,page,size), {}, stdPostHeader);
                opt = JSON.stringify(opt);
                req.save(opt, function (data) {
                    callback(data.result.message, data.data);
                })
            },
            createWish: function(updateObj, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/createWish'.format(backOfficeHost), {}, stdPostHeader);
                req.save(updateObj, function (data) {
                    callback(data.result.message, data.data);
                })
            },
            updateWish: function(wishId, updateObj, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/updateWish/{1}'.format(backOfficeHost, wishId), {}, stdPostHeader);
                req.save(updateObj, function (data) {
                    callback(data.result.message, data.data);
                })
            },
            updateUserWish: function(wishId, updateObj, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/updateUserWish/{1}'.format(backOfficeHost, wishId), {}, stdPostHeader);
                req.save(updateObj, function (data) {
                    callback(data.result.message, data.data);
                })
            },
            deleteWish: function(delObj, callback){
                var req = $resource('http://{0}/rest/v1.0/backoffice/wish/deleteWish'.format(backOfficeHost), {}, stdPostHeader);
                // accepts pure JSON arrays -> $in operator handled in backend controller
                delObj = JSON.stringify(delObj);
                req.save({delObj:delObj}, function (data) {
                    callback(data.result.message, data.data);
                })
            }
        }
    })
;
